import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import swal, { SweetAlertType } from 'sweetalert2';
import {HttpService} from "@core/services/http.service";
import {HttpClient} from "@angular/common/http";

@Component({
    selector: 'app-c-mindmap-tool',
    templateUrl: './c-mindmap-tool.component.html',
    styleUrls: ['./c-mindmap-tool.component.less']
})
export class CMindmapToolComponent implements OnInit {

    @Output() onChange = new EventEmitter<any>();
    @Output() onChangeTxt = new EventEmitter<any>();
    @Output() onDelete = new EventEmitter<any>();

    targetData;
    lineRadio = 'online';

    @Input() comeList;

    @Input() rightData;

    checkChange(){

    }

    set rightText(value){
        this.rightData.text = value;
        this.onChangeTxt.emit(this.rightData);
    }

    get rightText(){
        return this.rightData.text;
    }

    constructor(public http: HttpService, public httpClient: HttpClient) { }

    ngOnInit() {
        this.lineRadio = this.rightData.fillData.line;
    }


    // fileChange($event) {
    //     const file: File = $event.target.files[0];
    //     const myReader: FileReader = new FileReader();
    //     const that = this;
    //     myReader.onloadend = (loadEvent: any) => {
    //         that.rightData.src = loadEvent.target.result;
    //     };
    //     myReader.readAsDataURL(file);
    // }

    deleteComponent() {
        this.onDelete.emit();
    }

    deleteOption(i) {
        this.rightData.selectData.splice(i, 1);
    }

    lineChange(lineRadio){
        if(lineRadio == 'online'){
            this.rightData.fillData.line = lineRadio
        }else{
            this.rightData.fillData.line = lineRadio;
        }
    }
    addOption() {
        this.rightData.selectData.push({
            'value': '新增节点'
        });
    }
    save() {
        swal(`保存成功`, '', 'info');
    }
}
